<template>
	<zui-box>
		<zui-navbar title="兑换"></zui-navbar>
		<u-gap height="30rpx"></u-gap>
		<zui-flat bgColor="#EEAE4F">
			<view class="item">
				<view class="col_text">可兑换金元</view>
				<view class="col_price">{{ info.gold_num }}</view>
			</view>
			<view class="item">
				<view class="col_text">今日可兑换购物券</view>
				<view class="col_price">{{ info.exchange_num }}</view>
			</view>
		</zui-flat>

		<zui-flat><u-input v-model="account" shape="circle" placeholder="请输入兑换的购物券数量" border="none" color="#fff" clearable></u-input></zui-flat>
		<!-- <zui-start padding="30rpx"><view class="start_name">每次兑换需要收取4%税</view></zui-start> -->
		<zui-flat>
			<u-input  v-show="!is_password" v-model="password" placeholder="请输入支付密码" border="none" clearable color="#fff" >
				<template slot="suffix">
					<u-icon v-if="is_password" @click="is_password = false" :name="require('@/static/img/eye01.png')"></u-icon>
					<u-icon v-if="!is_password" @click="is_password = true" :name="require('@/static/img/eye02.png')"></u-icon>
				</template>
			</u-input>
			<u-input v-show="is_password" v-model="password" placeholder="请输入支付密码" border="none" clearable color="#fff" :password="is_password">
				<template slot="suffix">
					<u-icon v-if="is_password" @click="is_password = false" :name="require('@/static/img/eye01.png')"></u-icon>
					<u-icon v-if="!is_password" @click="is_password = true" :name="require('@/static/img/eye02.png')"></u-icon>
				</template>
			</u-input>
		</zui-flat>

		<u-gap height="264rpx"></u-gap>

		<zui-button bgColor="#AA334F" @fun="save">确定</zui-button>
	</zui-box>
</template>

<script>
export default {
	data() {
		return {
			info: {},
			account: '',
			password: '',
			is_password: true
		};
	},
	onLoad() {
		this.get_info();
	},
	methods: {
		get_info() {
			uni.$u.http
				.get('/app/vouchers/getExchangeGoldNum', {
					params: {},
					custom: {
						auth: true,
						toast: true,
						catch: true
					}
				})
				.then(res => {
					this.info = res;
				})
				.catch(err => {});
		},
		save() {
			if (!this.account) return this.say('请输入兑换的购物券数量');
			if (!this.password) return this.say('请输入支付密码');
			uni.$u.http
				.post(
					'/app/vouchers/exchangeVouchers',
					{
						vouchers_num: this.account,
						password: this.password,
					},
					{
						params: {},
						custom: {
							auth: true,
							toast: true,
							catch: true
						}
					}
				)
				.then(res => {
					uni.$u.toast('成功');
					this.password = '';
					this.account = '';
					setTimeout(() => {
						uni.navigateBack();
					}, 1200);
				})
				.catch(err => {});
		}
	}
};
</script>

<style lang="scss" scoped>
/deep/.u-input__content__field-wrapper__field {
	height: 100rpx !important;
}
/deep/.flat {
	width: 100%;
	padding: 20rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 30rpx;
	.item {
		width: 50%;
		padding: 30rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		color: #fff;
		.col_price {
			margin-top: 20rpx;
		}
	}
}

.start_name {
	padding: 0 30rpx;
	box-sizing: border-box;
	font-size: 22rpx;
	color: #fff;
}
</style>
